# = test.photo.15.rb -  Photo Themes Test
# 
# See LICENSE.txt for licensing details.
#
#To test the functionality for "Changes in  how my gallery looks" under settings for My Photos
require 'watir'
require 'watir/WindowHelper'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'

class TC_PhotosChangeTheme_test < Test::Unit::TestCase
    
    def startup			
      $GalleryName = randomChar(15)
      @@ie = Watir::IE.start($SITE_URL)
    end
  
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end

    def test_01_verifyHomeText
      assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
     if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))      
    end
    
    def test_07_verifyControlPanelTabBarLinks
      assert_equal $SITE_URL + 'controlpanel/default.aspx', ie.link(:text, 'Dashboard').href
      assert_equal $SITE_URL + 'controlpanel/blogs', ie.link(:text, 'My Blogs').href
      assert_equal $SITE_URL + 'controlpanel/photos/', ie.link(:text, 'My Photos').href
      assert_equal $SITE_URL + 'controlpanel/files', ie.link(:text, 'My Files').href
      assert_equal $SITE_URL + 'controlpanel/moderation', ie.link(:text, 'Forums Moderation').href
      assert_equal $SITE_URL + 'controlpanel/Setup.aspx', ie.link(:text, 'Administration').href
      assert_equal $SITE_URL + 'controlpanel/Reporting/default.aspx', ie.link(:text, 'Reporting').href
    end
    
    def test_08_navigateToPhotoGalleryThemePage
      ie.link(:text, 'My Photos').click
      
      assert(ie.link(:text, 'Select Photo Gallery to Manage').exists?)
      ie.link(:text, 'Select Photo Gallery to Manage').click
      
      assert(ie.link(:text, 'sample').exists?)
      ie.link(:text, 'sample').click
      
      assert(ie.cell(:text, 'Settings').exists?)
      ie.cell(:text, 'Settings').click
      
      assert(ie.link(:text, /Change How My Gallery Looks/).exists?)
      ie.link(:text, /Change How My Gallery Looks/).click      
    end
    
    def test_09_verifyLinksExistOnPhotoGalleryThemePage
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
      assert(ie.link(:text, 'Title and Description').exists?)
      assert(ie.link(:text, 'Change How My Gallery Looks').exists?)
      assert(ie.link(:text, 'About My Gallery').exists?)
      assert(ie.link(:text, 'Post Categorization Settings').exists?)
      assert(ie.link(:text, 'Default Post Settings').exists?)
      assert(ie.link(:text, 'Advanced Post Settings').exists?)
      assert(ie.link(:text, 'Advanced Photo Settings').exists?)
      assert(ie.link(:text, 'Advanced Syndication Settings').exists?)
      assert(ie.link(:text, 'Sample').exists?)
      #assert(ie.link(:id, /Skin1_HelpIcon1$/).exists?)
      assert(ie.link(:id, /TopLeft_HyperLink1$/).exists?)
      assert(ie.link(:id, /Layout1_Helpicon3$/).exists?)
      assert(ie.link(:id, /Layout1_Helpicon4$/).exists?)
      assert(ie.link(:id, /SaveButton$/).exists?)
      assert(ie.link(:id, /EulaHyperlink$/).exists?)
      assert(ie.link(:text, 'Telligent').exists?)
      
    end
    
    def test_10_verifyFieldsExistOnPhotoGalleryThemePage
      sleep 5
      #assert(ie.select_list(:id, /Themes$/).exists?)
      assert(ie.select_list(:id, /PicturesSortBy$/).exists?)
      assert(ie.text_field(:id, /PictureListingColumns$/).exists?)
      assert(ie.text_field(:id, /PictureListingRows$/).exists?)
    end
    
    def test_11_changePhotoTheme
      sleep 5
      #ie.select_list(:id, /Themes$/).select(/Glimmer/)
      #assert(ie.contains_text('This gallery skin uses avatars'))
      assert(ie.select_list(:id,/PicturesSortBy$/).exists?)
      ie.text_field(:id, /PictureListingColumns$/).set '6'
      ie.text_field(:id, /PictureListingRows$/).set '5'
      ie.select_list(:id,/PicturesSortBy$/).set('Rating (Ascending)')
      sleep 3
      assert(ie.link(:id, /SaveButton$/).exists?)
      ie.link(:id, /SaveButton$/).click
      sleep 5 
      
      assert(ie.contains_text('Your changes have been saved successfully'))
    end

end